package com.niit.mall.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.niit.mall.order.domain.dto.OrderItemDTO;
import com.niit.mall.order.domain.dto.OrderOperateHistoryDTO;
import com.niit.mall.order.domain.po.OrderItem;
import com.niit.mall.order.domain.po.OrderOperateHistory;
import com.niit.mall.order.mapper.OrderOperateHistoryMapper;
import com.niit.mall.order.service.IOrderOperateHistoryService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


/**
 * @BelongsProject:pardo_mall_backendd
 * @BelongsPackage: com.niit.mall.order.service.impl
 * @Author: XihenXi
 * @CreateTime: 2025-06-17  16:52
 * @Description: TODO
 * @Version: 1.0
 */

@Service
public class OrderOperateHistoryServiceImpl extends ServiceImpl<OrderOperateHistoryMapper, OrderOperateHistory> implements IOrderOperateHistoryService {

    /**
     * 根据订单id查询订单操作记录
     * @param id 订单id
     * @return 订单操作记录
     */
    @Override
    public List<OrderOperateHistoryDTO> getByOrderId(Long id) {
        // 执行查询
        List<OrderOperateHistory> orderOperateHistoriesList = lambdaQuery()
                .eq(OrderOperateHistory::getOrderId, id)
                .list();
        // 手动转换为 DTO 列表
        return orderOperateHistoriesList.stream()
                .map(item -> {
                    OrderOperateHistoryDTO dto = new OrderOperateHistoryDTO();
                    dto.setId(item.getId());
                    dto.setOrderId(item.getOrderId());
                    dto.setOperateUser(item.getOperateUser());
                    dto.setOperateTime(item.getOperateTime());
                    dto.setOrderStatus(item.getOrderStatus());
                    dto.setNote(item.getNote());
                    dto.setCreateDate(item.getCreateDate());
                    dto.setUpdateDate(item.getUpdateDate());
                    return dto;
                })
                .collect(Collectors.toList());
    }
}
